import Vue from 'vue'
import Router from 'vue-router'
// import { Search } from 'vant';

Vue.use(Router)

export default new Router({
  base: "/",
  mode: 'hash',
  routes: [
    { // 首页
      path: '/', name: 'Index', 
      component: resolve => require(['@/pages/index/index'], resolve),
      meta: {
        keepAlive: true // 需要被缓存
      }
    },
    // 登录
    {
      path: '/login',
      name: 'Login',
      component: resolve => require(['@/pages/login/login'], resolve)
    },
    // 注册
    {
      path: '/register',
      name: 'Register',
      component: resolve => require(['@/pages/register/register'], resolve)
    },
    // 忘记登录密码
    {
      path: '/forgotPw',
      name: 'ForgotPw',
      component: resolve => require(['@/pages/forgotPw/forgotPw'], resolve)
    },
    // 用户协议
    {
      path: '/protocol',
      name: 'Protocol',
      component: resolve => require(['@/pages/protocol/protocol'], resolve)
    },
    // 我的
    {
      path: '/search',
      name: 'Search',
      component: resolve => require(['@/pages/search/search'], resolve)
    },
    // 查询
    {
      path: '/center',
      name: 'Center',
      component: resolve => require(['@/pages/center/center'], resolve)
    },
    // 资质服务
    {
      path: '/aptitude',
      name: 'Aptitude',
      component: resolve => require(['@/pages/aptitude/aptitude'], resolve)
    },
    // 资质、安许办理报价、资质托管
    {
      path: '/quote/:id',
      name: 'quote',
      component: resolve => require(['@/pages/quote/quote'], resolve)
    },
    // 资质买卖
    {
      path: '/aptitudeShop/:id',
      name: 'AptitudeSHop',
      component: resolve => require(['@/pages/aptitudeShop/aptitudeShop'], resolve)
    },
    // 资质标准
    {
      path: '/standard/:id',
      name: 'Standard',
      component: resolve => require(['@/pages/standard/standard'], resolve)
    },
    // 资质标准列表
    {
      path: '/standardList/:id',
      name: 'StandardList',
      component: resolve => require(['@/pages/standardList/standardList'], resolve)
    },
    // 资质标准详情
    {
      path: '/standardDetail/:id',
      name: 'StandardDetail',
      component: resolve => require(['@/pages/standardDetail/standardDetail'], resolve)
    },
    // 证书代办
    {
      path: '/certificate',
      name: 'Certificate',
      component: resolve => require(['@/pages/certificate/certificate'], resolve)
    },
    // 证书培训
    {
      path: '/train',
      name: 'train',
      component: resolve => require(['@/pages/train/train'], resolve)
    },
    // 三类模考
    {
      path: '/threeTest',
      name: 'ThreeTest',
      component: resolve => require(['@/pages/threeTest/threeTest'], resolve)
    },
    // 企业聘证
    {
      path: '/employ/:id',
      name: 'Employ',
      component: resolve => require(['@/pages/employ/employ'], resolve)
    },
    // 证书挂靠
    {
      path: '/anchored',
      name: 'Anchored',
      component: resolve => require(['@/pages/anchored/anchored'], resolve)
    },
    // 业务查询
    {
      path: '/business',
      name: 'Business',
      component: resolve => require(['@/pages/business/business'], resolve)
    },
    // 设置
    {
      path: '/set',
      name: 'Set',
      component: resolve => require(['@/pages/set/set'], resolve)
    },
    // 意见反馈
    {
      path: '/feedBack',
      name: 'Feedback',
      component: resolve => require(['@/pages/feedBack/feedBack'], resolve)
    },
    // 关于我们
    {
      path: '/aboutUs',
      name: 'AboutUs',
      component: resolve => require(['@/pages/aboutUs/aboutUs'], resolve)
    },
    // 清除缓存
    {
      path: '/clear',
      name: 'Clear',
      component: resolve => require(['@/pages/clear/clear'], resolve)
    },
    // 找回支付密码
    {
      path: '/foundPw',
      name: 'FoundPw',
      component: resolve => require(['@/pages/foundPw/foundPw'], resolve)
    },
    // 修改支付密码
    {
      path: '/editPw',
      name: 'EditPw',
      component: resolve => require(['@/pages/editPw/editPw'], resolve)
    },
    //绑定手机号
    {
      path: '/binding',
      name: 'Binding',
      component: resolve => require(['@/pages/binding/binding'], resolve)
    },
    //修改昵称
    {
      path: '/changeName',
      name: 'ChangeName',
      component: resolve => require(['@/pages/changeName/changeName'], resolve)
    },
    // 建造师查询
    {
      path: '/builders',
      name: 'Builders',
      component: resolve => require(['@/pages/builders/builders'], resolve)
    },
    // 三类人员查询
    {
      path: '/peoples',
      name: 'Peoples',
      component: resolve => require(['@/pages/peoples/peoples'], resolve)
    },
    // 八大员查询
    {
      path: '/occupation',
      name: 'Occupation',
      component: resolve => require(['@/pages/occupation/occupation'], resolve)
    },
    // 企业资质查询
    {
      path: '/companies',
      name: 'Companies',
      component: resolve => require(['@/pages/companies/companies'], resolve)
    },
    // 企业资质详情
    {
      path: '/companiesDetail/:id',
      name: 'CompaniesDetail',
      component: resolve => require(['@/pages/companiesDetail/companiesDetail'], resolve)
    },
    // 查询结果
    {
      path: '/result/:data',
      name: 'Result',
      component: resolve => require(['@/pages/result/result'], resolve)
    },
    // 建筑资讯
    {
      path: '/newsList',
      name: 'NewsList',
      component: resolve => require(['@/pages/newsList/newsList'], resolve)
    },
    // 资讯详情
    {
      path: '/newsDetail/:id',
      name: 'NewsDetail',
      component: resolve => require(['@/pages/newsDetail/newsDetail'], resolve)
    },
    // 用户信息
    {
      path: '/userInfo',
      name: 'UserInfo',
      component: resolve => require(['@/pages/userInfo/userInfo'], resolve)
    },
    // 页面出错
    {
      path: '*',
      name: 'Error',
      component: Error
    },
  ],
  scrollBehavior (to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      if (from.meta.keepAlive) {
        // 在触发路由切换时，如果当前页面需要缓存数据，那么在其路由的meta.savedPostion中保存当前页面的滚动位置数据
        from.meta.savedPosition = document.body.scrollTop || document.documentElement.scrollTop;
      }
      // 切换路由时，检测其meta.savedPosition, 如果有值则将其滚动到缓存位置       
      return { x: 0, y: to.meta.savedPosition || 0 }
    }
  }
})
